//
//  ButtonScrollView.m
//  DaMaoMall
//
//  Created by HXHL-wally on 16/7/13.
//  Copyright © 2016年 daMao-wally. All rights reserved.
//

#import "ButtonScrollView.h"

@implementation ButtonScrollView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
+ (instancetype)ButtonScrollViewWithFarme:(CGRect)farme delegate:(id<ButtonScrollViewDelegate>)delegate ImageURLStringsGroup:(NSArray *)urlArray titlesGroup:(NSArray *)titlesArray
{
    ButtonScrollView * scrollView = [[ButtonScrollView alloc]initWithFrame:farme];
    scrollView.backgroundColor = [UIColor whiteColor];
    scrollView.contentSize = CGSizeMake(105*urlArray.count+urlArray.count, 0);
    // 使 button 区域可以滑动
    scrollView.panGestureRecognizer.delaysTouchesBegan = YES;
    
    for (int i = 0 ; i < urlArray.count; i++) {
        
        UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(105*i+25, 15, 60, 60);
        [button setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",urlArray[i]]] forState:UIControlStateNormal];
        button.tag = 1000+i;
        [button addTarget:scrollView action:@selector(scrollViewItem:) forControlEvents:UIControlEventTouchUpInside];
        [scrollView addSubview:button];
        
        UILabel * label = [[UILabel alloc ]initWithFrame:CGRectMake(105*i+5, 80, 100, 20)];
        label.text = titlesArray[i];
        label.font = [UIFont systemFontOfSize:14];
        label.textAlignment = NSTextAlignmentCenter;
        [scrollView addSubview:label];
        
    }
    
    return scrollView;
}

- (void)scrollViewItem:(UIButton *)index
{
    [self.buttonScrollViewDelegate didSelectScrollButtonAtIndex:index.tag];
    
}

@end
